Now let's get our equipment storage utils talking to our shop.
So when somebody buys something from the shop on the server side, it's going to be recorded here and
then the players are going to have a record of what they own.
We'll be able to store that off.
Let's go to our Activate Shop script.
I have it open.
That's the server side shop script.
If you can't find it, we can right click and show and explore.
It is in the workspace.
Under shop, under bell, under bell top activate shop script.
This is where we do the money subtraction and we equip the player with the item.
All right.
So I'm going to do a little bit of code cleanup right here.
I'm not going to use the item price coming from the client.
It's just bothering me too much.
Right.
Because people can hack it and you don't want a player taking advantage of your game.
All right.
Right here.
We're going to have to do something about that.
How do we subtract the price?
Well, we do have an a cloned item.
We called it item clone.
We could put a price on the item and use that value.
Then that price is going to come from the item that we purchased.
We can get rid of this if statement.
Let's go ahead and fix our indents.
And we just have to make sure this price is on our items.
Let's go to replicated storage.
Fabulous, Lemon.
Well, that was 2000, right?
So we got an int value.
There we go.
And we'll call that price and then we'll make the value 2000.
Now, the one thing that we should do is we need to be able we should write code to actually grab the
prices on the client side.
Right now, we still have to coordinate the price on the item to the price in the shop.
A little bit of extra level of work.
We've got to do that we could make mistakes on, but that's further down the road if we want to go that
route.
So the simple pistol, we also need a price that's in value.
And we'll call that price.
So everything in your shop is going to need a price based on this new change.
And what was the simple pitch to 1000?
All right, let's test it out.
I hit the play button here.
We'll go to view.
Output a little bit.
Output.
Just look for some red stuff there.
And I have 24,600 points currently.
I'm going to hit the buy button.
There's my simple pistol.
This should cost 1000.
This should go down to 23 600.
Boom.
23.
600.
Nice.
Still not talking to our equipment storage utils yet though, but we're just testing this out.
This should go down 2000 to 20 1 to 600.
Nice.
All right, so we're still going to lose our stuff.
Let's go ahead and start working on that.
I'm in my activate shop script right now, and this is the server side shop script.
When we buy an item, we're going to equip the player and subtract the money.
We need to record the information that happened here in our equip storage utils so we could save to
the database and we don't lose the information.
That is, we don't lose the equipment for our players.
Let's make a variable up near the top local equip utils.
This is going to be pointing to our module script.
We're going to require the module script.
We've got to do game dot server script, service, dot, equip, storage, utils to get a reference
to it.
And then this is going to have all of the information for our storage utils.
Before we call equip storage utils.
We need a helper function now.
I'll do a local function and the helper function will be make info table and we'll pass the item that
we just bought.
So this is going to be the cloned item down here, this item clone and make info table.
I'm going to make a table do local call this item table.
And as an equal sign curly bracket, we're going to need a key value pair.
I'll do name equals item, dot name.
And that way we're going to have at least the item name, which is currently all we're using, but we
want to use those configuration values.
So let's get a variable for config and I have my item.
Find first child.
Configuration folder on at least the simple pistol.
So you look in here, there's a configuration.
Oh, nice.
But the simple lemon doesn't have or the fabulous lemon doesn't have it.
But that's why we're doing a fine first child.
So we'll do an if config just to make sure it exists.
If it does exist, let's loop through all of the configuration values.
Right now we only have cooldown on the pistol, but we may want to add more.
We might want to put ammo reserved ammo.
So for I and V in pairs for the config colon get children, you need to have extra parentheses there
do we will have our item table square bracket V is going to be the thing under the configuration.
I is going to be like one, two, three, four.
So this is going to be a cool down if I do v dot name that's going to actually say cool down equal to
V dot value.
That is that value there, which is a one, right?
So if you have ammo and ammo is equal to six, this right here will be ammo, this will be six.
You get the idea right.
We'll get down to here, will return our item table and then where are we going to use that?
Well, we're going to use that in our shop re on server event where we buy our items.
So we clone the item and then we need to get a table with the item info.
So do local item.
Oh my gosh.
Item table make info table passed in the item clone.
Right.
So we're going to pass that in.
That's going to be right there.
We're going to get an item table with all of our items.
We're going to return it.
It's going to be right here and we're going to be able to use it after we subtract the price from our
points value.
Let's scroll up a little bit.
Let's make a call to our equip utils add item to player's inventory.
There we go.
We're going to pass in the player and then we're going to pass in the item table.
Item table, the one we got from make info table right here.
Now let's go over to our module script, equip storage, utils and add items to player inventory.
Doesn't have anything in it.
That's all right.
That's good.
And change that.
We need to add this table to this main table using the player as the key.
So we have all of the items for all of the players and then when we do saves, we'll be able to update
players as they're playing and they're buying stuff.
Right?
So let's check to see if there is not equipment table player data in this table for that particular
player.
Right.
So if the player doesn't have any equipment, didn't buy any equipment and this is the first thing they're
buying, what we need to do is initialize that table for them.
Right.
Oop, get don't forget your equal sign.
Right.
So we're going to initialize that table so they don't get an error under the if statement.
Let's get a table dot insert and then we have our equipment table for the player.
It might be empty, but it won't be nil.
And then we'll get this table right here.
Item info Table.
It's got our item info that we just sent over.
We're going to paste that there.
And now the equipment table for the player is going to have all the stuff in it.
Let's go ahead and do a print statement for our entire equipment table.
And since we're testing with only one player, it's not going to be a big deal, right?
All right.
Let's try this thing out.
I'm going to hit play.
And then while it's starting up, I'm going to go to my view output.
So we have an output window and then go to these three dots, make sure log mode is off.
That way you can see the entire table rather than just the hexadecimal address.
So logger mode unchecked.
And let's shrink this down a little bit while we're making a purchase.
Come over here.
Bam.
Simple pistol.
Buy it.
Cool.
We can open it up.
I've got to make this bigger again.
Open it up.
This right here is a reference to our player.
We are in the equipment table.
There's the player.
What does the player have?
Are the player has a table here that has cooldown and the name of the instrument or the name of the
equipment.
The item is simple pistol.
What happens if we get the lemon?
Ding.
Fabulous.
Lemon.
Buy it.
All right.
We've got two things.
Scroll down.
Here's the updated equipment table.
And we have our player right here.
Let's open the equipment table for the player.
Look at that.
We got our simple pistol with our cool down in it.
We have our fabulous lemon.
It just has a name.
So we have two items under that player.
That's pretty cool.
We can work with that.
Let's go ahead and start saving that stuff off.